package com.ruoyi.report.controller;

import com.ruoyi.api.system.utils.poi.ExcelUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.report.domain.ReportPosition;
import com.ruoyi.report.domain.ReportUser;
import com.ruoyi.report.service.IReportUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Calendar;
import java.util.List;

@Controller
@RequestMapping("/report/user")
public class ReportUserController extends BaseController {

    private String prefix = "report/user";

    @Autowired
    private IReportUserService reportUserService;

    /**
     * 人员花名册
     * @return
     */
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询人员详细信息
     * @param reportUser
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReportUser reportUser)
    {
        startPage();
        List<ReportUser> list = reportUserService.selectUserReportList(reportUser);
        return getDataTable(list);
    }

    /**
     * 导出人员花名册
     */
    @Log(title = "花名册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReportUser reportUser)
    {
        List<ReportUser> list = reportUserService.selectUserReportList(reportUser);
        ExcelUtil<ReportUser> util = new ExcelUtil<ReportUser>(ReportUser.class);
        return util.exportExcel(list, "花名册");
    }

    /**
     * 人员花名册
     * @return
     */
    @GetMapping("/report")
    public String report(ModelMap mmap)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        String reportMonth = DateUtils.parseDateToStr("yyyy-MM", calendar.getTime());
        mmap.put("reportMonth", reportMonth);
        return prefix + "/report";
    }

    /**
     * 查询人员详细信息
     * @param reportUser
     * @return
     */
    @PostMapping("/report_list")
    @ResponseBody
    public TableDataInfo report_list(ReportUser reportUser)
    {
        startPage();
        List<ReportUser> list = reportUserService.selectReportUserList(reportUser);
        return getDataTable(list);
    }

    /**
     * 导出人员花名册
     */
    @Log(title = "花名册", businessType = BusinessType.EXPORT)
    @PostMapping("/report_export")
    @ResponseBody
    public AjaxResult report_export(ReportUser reportUser)
    {
        List<ReportUser> list = reportUserService.selectReportUserList(reportUser);
        ExcelUtil<ReportUser> util = new ExcelUtil<ReportUser>(ReportUser.class);
        return util.exportExcel(list, "花名册");
    }
}
